package cn.edu.tsinghua.smxq.mobilecity.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import cn.edu.tsinghua.smxq.mobilecity.po.FoodCategory;
import cn.edu.tsinghua.smxq.mobilecity.utils.DBUtils;

public class FoodCategoryDAO {
	
	public FoodCategory getById(int id) throws SQLException {
		FoodCategory foodCategory = null;
		Connection conn = DBUtils.Connect();
		ResultSet rs = null;
		PreparedStatement pstmt = conn
				.prepareStatement("SELECT * FROM mobilecity.foodcategory WHERE id=?");
		pstmt.setInt(1, id);
		rs = pstmt.executeQuery();
		if (rs.next()) {
			foodCategory = new FoodCategory();
			foodCategory.setId(rs.getInt("id"));
			foodCategory.setCategory(rs.getString("category"));
		}
		rs.close();
		pstmt.close();
		conn.close();
		return foodCategory;
	}

}
